package com.boang.controller.house;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boang.entity.Unit;
import com.boang.resp.Result;
import com.boang.service.UnitService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
@author:22567
@date:2025/3/3 16:53
*/
@Tag(name = "单元管理unit")
@RestController
@RequestMapping("/unit")
public class UnitController {
    //    单元管理
    @Autowired
    private UnitService unitService;


    //-------------------添加--------------------
    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody Unit unit) {
        return Result.ok(unitService.save(unit));
    }

    //-------------------修改--------------------
    @PutMapping("/update")
    public Result<Boolean> update(@RequestBody Unit unit) {
        return Result.ok(unitService.updateById(unit));
    }
    //-------------------删除--------------------

    @DeleteMapping("/remove")
    public Result<Boolean> remove(int id) {
        return Result.ok(unitService.removeById(id));
    }

    //-------------------根据楼号查询单元--------------------
    @GetMapping("/findBybuildId")
    public List<Unit> findByYourColumn(@RequestParam("buildId") String buildId) {
        return unitService.getByBuildId(buildId);
    }

    //-------------------分页查询--------------------
    @GetMapping("/page")
    public Result<Page<Unit>> page(int pageNum, int pageSize) {
        Page page = new Page(pageNum, pageSize);
        return Result.ok(unitService.page(page));
    }

}
